package com.example.home.adapter.provider

import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.common.RouterPath
import com.example.home.R
import com.example.home.adapter.NominateItemType
import com.example.home.databinding.ItemHomeFollowCardViewBinding
import com.example.entity.BaseEntity
import com.example.home.entity.viewdata.FollowCardViewData

class FollowCardProvider : BaseItemProvider<BaseEntity>() {
    override val itemViewType: Int = NominateItemType.FOLLOW_CARD_VIEW
    override val layoutId: Int = R.layout.item_home_follow_card_view

    override fun onViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        DataBindingUtil.bind<ItemHomeFollowCardViewBinding>(viewHolder.itemView)
    }

    override fun convert(helper: BaseViewHolder, item: BaseEntity) {
        var dataBinding = helper.getBinding<ItemHomeFollowCardViewBinding>()
        if (item!=null && dataBinding!=null){
            var entity = item as FollowCardViewData
            //添加点击事件
            dataBinding.ivFollowCover.setOnClickListener {
                //点击进入详情页面
                ARouter.getInstance().build(RouterPath.PATH_ACTIVITY_VIDEO)
                    .withString("playerUrl",entity.playerUrl).navigation()
            }
            //绑定适配数据
            dataBinding.viewData = entity

            dataBinding.executePendingBindings()
        }

    }
}